#include "Window.h"
#include "stm32f10x.h"
#define ID_FRAMEWIN (GUI_ID_USER+2)
#define ID_MULTIEDIT (GUI_ID_USER+3)
extern USART cout;
FRAMEWIN_Handle hFra;
MULTIEDIT_HANDLE hMulti;

static void _cbFra(WM_MESSAGE* pMsg)
{
	switch(pMsg->MsgId)
	{
		case WM_CREATE:
			FRAMEWIN_AddCloseButton(pMsg->hWin, FRAMEWIN_BUTTON_RIGHT, 0);
			break;

		case WM_PAINT:
		{
			uint32_t bt;
			char buf[256] = {"0:/Reply/"};
			FRAMEWIN_GetText(hFra, buf+strlen(buf), sizeof(buf)-strlen(buf));
			res = f_open(&fil,buf,FA_READ);
			if(res != FR_OK)
				cout<<"file open fail"<<endl<<"res:"<<res<<endl<<__FILE__<<':'<<__LINE__<<endl;
			res = f_read(&fil,buf,256,&bt);
			buf[bt] = '\0';
			if(res != FR_OK)
				cout<<"file read fail"<<endl<<"res:"<<res<<endl<<__FILE__<<':'<<__LINE__<<endl;
			f_close(&fil);
			MULTIEDIT_SetText(hMulti, buf);
		}
		break;

		default:
			FRAMEWIN_Callback(pMsg);
			break;
	}
}

void CreateDispWindow(GUI_HWIN hWin, const char* Title)
{
	hFra = FRAMEWIN_CreateEx(10, 10, 300, 220, hWin, WM_CF_SHOW, FRAMEWIN_CF_ACTIVE, ID_FRAMEWIN, Title, _cbFra);
	hMulti = MULTIEDIT_CreateEx(0, 0, 290, 200, WM_GetClientWindow(hFra), \
	                            WM_CF_SHOW, MULTIEDIT_CF_AUTOSCROLLBAR_V | MULTIEDIT_CF_READONLY, ID_MULTIEDIT, 1024, "");
	MULTIEDIT_SetFont(hMulti, &UTF_8);//设置编辑框字体
	MULTIEDIT_SetBkColor(hMulti,MULTIEDIT_CI_READONLY,GUI_WHITE);//设置编辑框只读,背景色白色
	FRAMEWIN_SetFont(hFra,&UTF_8);
}
